% Phase velocity window configuration
% August 2016
% Hamzeh Sadeghisorkhani

%% Average velocity panel
h.panel(5)= uipanel(mainfig,'visible','off','Position',[.235 .15 .74 .8]);
set(h.panel(5),'BackgroundColor',panel_color)



%% Text boxes
%-------------------------------- Dispersion Measurments
uicontrol(h.panel(5),'Style','text', 'String','Dispersion Measurments',...
    'HorizontalAlignment','left','Fontweight','bold',...
    'Units','normalized','Position',[.01 .92 .4 .05],...
    'BackgroundColor',panel_color);
            

uicontrol(h.panel(5),'Style','text', 'String','Cmin',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .84 .2 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(5),'Style','text', 'String','Cmax',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .78 .2 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(5),'Style','text', 'String','T1',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.55 .84 .2 .05],...
    'BackgroundColor',panel_color);
            
uicontrol(h.panel(5),'Style','text', 'String','T2',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.55 .78 .2 .05],...
    'BackgroundColor',panel_color);
            

uicontrol(h.panel(5),'Style','text', 'String','Period Axis Scaling',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .69 .24 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(5),'Style','text', 'String','Measure Phase Velocity up to (distance/lambda) >=',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .61 .65 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(5),'Style','text', 'String','Measure Phase Velocity at Periods (sec) equal to',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .53 .65 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(5),'Style','text', 'String','SNR Criteria (Rejection)',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .4 .24 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(5),'Style','text', 'String','SNR Threshold',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.1 .32 .24 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(5),'Style','text', 'String','Noise Window (sec)',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.1 .24 .24 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(5),'Style','text', 'String','Colorful Points at Different Cycles',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .13 .65 .05],...
    'BackgroundColor',panel_color);



%% Editable text 
%-------------------------------- Dispersion Measurments
h2.vmin= uicontrol(h.panel(5),'Style','edit', 'String',params.vmin,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.14 .855 .1 .04],...
    'BackgroundColor','w');

h2.vmax= uicontrol(h.panel(5),'Style','edit', 'String',params.vmax,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.14 .795 .1 .04],...
    'BackgroundColor','w');

h2.T1= uicontrol(h.panel(5),'Style','edit', 'String',params.T1,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.61 .855 .1 .04],...
    'BackgroundColor','w');

h2.T2= uicontrol(h.panel(5),'Style','edit', 'String',params.T2,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.61 .795 .1 .04],...
    'BackgroundColor','w');

h2.radiobutton(1)= uibuttongroup(h.panel(5),'units','normalized','BackgroundColor',panel_color,...
    'bordertype','none','Position',[.27 .7 .4 .05]);

h2.radio(1) = uicontrol( h2.radiobutton(1), 'Style','Radio','String','Log',...
    'BackgroundColor',panel_color, 'units','normalized','position',[0 0 .5 1],'HandleVisibility','off');
h2.radio(2) = uicontrol( h2.radiobutton(1), 'Style','Radio','String','Linear',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.3 0 .5 1],'HandleVisibility','off');


h2.rlambda= uicontrol(h.panel(5),'Style','edit', 'String',params.rlambda,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.61 .625 .1 .04],...
    'BackgroundColor','w');

h2.measureperiods= uicontrol(h.panel(5),'Style','edit', 'String',params.measureperiods,...
    'HorizontalAlignment','left','Max',2,...
    'Units','normalized','Position',[.61 .23 .1 .35],...
    'BackgroundColor','w');


h2.SNRflag= uicontrol(h.panel(5),'Style','checkbox', 'String','',...
    'HorizontalAlignment','left','Value',1,...
    'Tag','SNRflag',...
    'Units','normalized','Position',[.35 .415 .1 .04],...
    'BackgroundColor',panel_color,'callback',@checkbox_cbk);

h2.SNR= uicontrol(h.panel(5),'Style','edit', 'String',params.SNR,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.32 .335 .1 .04],...
    'BackgroundColor','w');


h2.Nwin1= uicontrol(h.panel(5),'Style','edit', 'String',params.Nwin1,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.32 .255 .1 .04],...
    'BackgroundColor','w');

h2.Nwin2= uicontrol(h.panel(5),'Style','edit', 'String',params.Nwin2,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.45 .255 .1 .04],...
    'BackgroundColor','w');


h2.colorful= uicontrol(h.panel(5),'Style','checkbox', 'String','',...
    'HorizontalAlignment','left','Value',1,...
    'Tag','colorful',...
    'Units','normalized','Position',[.42 .145 .1 .04],...
    'BackgroundColor',panel_color,'callback',@checkbox_cbk);


%% Saving buttons

uicontrol(h.panel(5),'style','pushbutton', 'string','Default',...
    'ToolTipString','Load default setting','Tag','default5',...
    'units','normalized','position',[.1 .03 .18 .07], ...
    'callback',@default_cbk);

uicontrol(h.panel(5),'style','pushbutton', 'string','Latest',...
    'ToolTipString','Load latest setting','Tag','latest5',...
    'units','normalized','position',[.41 .03 .18 .07], ...
    'callback',@latest_cbk);

uicontrol(h.panel(5),'style','pushbutton', 'string','Save',...
    'ToolTipString','Save setting changes','Tag','save5',...
    'units','normalized','position',[.72 .03 .18 .07], ...
    'callback',@save_cbk);


%% Setting values
if strcmp(params.scale,'Log')
    set (h2.radio(1),'value',1);
    set (h2.radio(2),'value',0);
elseif strcmp(params.scale,'Linear')
    set (h2.radio(1),'value',0);
    set (h2.radio(2),'value',1);
end
% get(h2.radiobutton(1),'selectedobject')


if strcmp(params.SNRflag,'yes')
    set (h2.SNRflag,'value',1);    
    set (h2.SNR,'Enable','on');
    set (h2.Nwin1,'Enable','on');
    set (h2.Nwin2,'Enable','on');
elseif strcmp(params.SNRflag,'no')
    set (h2.SNRflag,'value',0);    
    set (h2.SNR,'Enable','off');
    set (h2.Nwin1,'Enable','off');
    set (h2.Nwin2,'Enable','off');
end

if strcmp(params.colorful,'yes')
    set (h2.colorful,'value',1);
elseif strcmp(params.SNRflag,'no')
    set (h2.colorful,'value',0);    
end
    